<template>
  <div class="wrapper">
		<div class="header">加群审核验证</div>
		<div class="content">
			<div class="friend_img">
				<img src="img/face_1.png" alt="">
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">账号</span>
						<span class="items_text">{{applyJoinInfo.From_Account}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">昵称</span>
						<span class="items_text">{{applyJoinInfo.GroupName}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info2">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">加群验证</span>
						<span class="items_text">附言</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
				<div class="text_area">
					<textarea ref="textareas"></textarea>
				</div>
			</div>
			<div class="check_btns">
				<button class="add_back" ref="reject">拒绝</button>
				<button class="add_friend" ref="agree">通过验证</button>
			</div>
		</div>
	</div>  
</template>
<script>
import Client from "../../config/common";
export default {
  data () {
    return {
      applyJoinInfo: {},

    }
  },

  created () {

    // 登录初始化
    this.initLogin();
  },

  methods: {

      // 登录初始化
			initLogin() {
				Client.login(this.getLoginInfo);
			},

			// 获得登录成功信息
			getLoginInfo(loginInfo) {
        let That = this;
				// 将 登录信息保存在 vue的data里
				this.loginInfo = loginInfo;
				Client.log("登录成功-start");
				Client.log(loginInfo);
				Client.log("登录成功-end");

        // 获取申请加入的人员信息
        if(!sessionStorage.applyJoinInfo){
          this.$router.push({path: '/groupApplyJoinList'});
          return ;
        }
        this.applyJoinInfo = JSON.parse(sessionStorage.applyJoinInfo);
        console.log("当前审核申请加群成员的信息-start");
        console.log(this.applyJoinInfo);
        console.log("当前审核申请加群成员的信息-end");

        // 审核通过
        $(this.$refs.agree).on("click", function(){
          That.handleApplyJoinGroupPendency("Agree");
        });

        // 审核不通过
        $(this.$refs.reject).on("click", function(){
          That.handleApplyJoinGroupPendency("Reject");
        });
      },

      //处理加群申请
      handleApplyJoinGroupPendency(_type) {
          let That = this;
          
          var options = {
              'GroupId': this.applyJoinInfo.GroupId, //群id
              'Applicant_Account': this.applyJoinInfo.From_Account, //申请人id
              'HandleMsg': _type, //Agree-同意 Reject-拒绝
              'Authentication': this.applyJoinInfo.Authentication, //申请凭证
              'ApprovalMsg': "", //处理附言
              'UserDefinedField': "",//用户自定义字段
              'MsgKey': this.applyJoinInfo.AddTime
              
          };

          //要删除的群未决消息
          let delApplyJoinGroupPendencys = {
              'DelMsgList': [
                  {
                      "From_Account": this.applyJoinInfo.From_Account,
                      "MsgSeq":0 ,
                      "MsgRandom": 1236
                  }
              ]
          };


          webim.handleApplyJoinGroupPendency(
              options,
              function (resp) {
                if(_type == "Agree"){
                  Client.log("审核成功");
                  Client.log(resp);
                  Client.log("审核成功");
                  alert("审核成功");
                }else if(_type == "Reject"){
                  Client.log("拒绝成功");
                  Client.log(resp);
                  Client.log("拒绝成功");
                  alert("拒绝成功");
                }

                  

                  //删除已处理的加群未决消息，否则下次登录的时候会重复收到加群未决消息
                  That.deleteApplyJoinGroupPendency(delApplyJoinGroupPendencys);

              },
              function (err) {
                if(_type == "Agree"){
                  Client.log("审核失败-start");
                  Client.log(err);
                  Client.log("审核失败-end");
                  alert(err);
                }else if(_type == "Reject"){
                  Client.log("拒绝失败-start");
                  Client.log(resp);
                  Client.log("拒绝失败-end");
                  alert(err);
                }
              }
          );
      },

      //删除已处理的加群未决消息
      deleteApplyJoinGroupPendency(opts) {
          let That = this;
          webim.deleteApplyJoinGroupPendency(opts,
              function (resp) {
                   Client.log("删除已处理的加群请求-start");
                   Client.log(resp);
                   Client.log("删除已处理的加群请求-end");
                   alert("删除已处理请求");
                   That.$router.push({path:'/groupList'});
                //   webim.Log.info('delete group pendency msg success');
              },
              function (err) {
                   Client.log("删除失败-start");
                   Client.log(err);
                   Client.log("删除失败-end");
                   alert(err.ErrorInfo);
                //   alert(err.ErrorInfo);
                //   webim.Log.error('delete group pendency msg failed');
              }
          );
          return;
      }

  }
}
</script>
<style lang="scss">
  @import "../../style/group_apply_join_check";
</style>
